package com.yedean.tenant;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 上下文
 *
 * @author yedean
 * @date 2022/9/20
 */
public class TenantContext {
    
    static ThreadLocal<Map<String,Object>> threadLocal = ThreadLocal.withInitial(LinkedHashMap::new);

    public static void addAttachment(String key, Object value){
        threadLocal.get().put(key,value);
    }

    public static void addAttachments(Map<String, Object> map){
        threadLocal.get().putAll(map);
    }

    public static String getShopId(){
        return String.valueOf(threadLocal.get().get("shopId"));
    }

    public static String getStoreId(){
        return String.valueOf(threadLocal.get().get("storeId"));
    }
    
    public static String getLoginUserId(){
        return String.valueOf(threadLocal.get().get("loginUserId"));
    }

    public static String getLoginUserName(){
        return String.valueOf(threadLocal.get().get("loginUserName")); 
    }

    public static Map<String, Object> getAttachments(){
        return threadLocal.get();
    }
    
    public static void clear(){
        threadLocal.remove();
    }
    
    
}
